import 'package:flutter/material.dart';

class LeftMenuView extends StatefulWidget {
  @override
  _LeftMenuViewState createState() => _LeftMenuViewState();
}

class _LeftMenuViewState extends State<LeftMenuView> {
  int _currentIndex = 0;

  List<String> _list = [
    "蔬菜",
    "肉禽蛋",
    "海鲜水产",
    "熟食凉菜",
    "速冻食品",
    "新鲜水果",
    "米面粮油",
    "特产干货",
    "酒水饮品",
    "美肤百货",
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 100,
      color: Colors.grey,
      child: ListView.builder(
          shrinkWrap: true,
          itemCount: _list.length,
          physics: AlwaysScrollableScrollPhysics(),
          itemBuilder: (context, index) {
            return GestureDetector(
              onTap: () {
                setState(() {
                  _currentIndex = index;
                });
              },
              child: Container(
                height: 60,
                color: _currentIndex == index ? Colors.white : Color(0xfff5f5f5),
                child: Row(
                  children: [
                    Container(
                        width: 3,
                        height: 20,
                        color: _currentIndex == index
                            ? Colors.red
                            : Colors.transparent),
                    Expanded(
                      child: Container(
                        alignment: Alignment.center,
                        child: Text(
                          _list[index],
                          style: TextStyle(fontSize: 18,),
                        ),
                      ),
                    )
                  ],
                ),
              ),
            );
          }),
    );
  }
}
